package ink.yql.controller;

import ink.yql.model.SolveLock;
import ink.yql.service.SolveLockService;
import ink.yql.util.RestObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YQL
 */
@RestController
@RequestMapping("/solve_lock")
public class SolveLockController {
    @Autowired
    private SolveLockService solveLockService;

    @GetMapping("/{pid}/{sendTime}")
    public RestObject getByPid(@PathVariable("pid") Integer pid, @PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请0求时间超时").build();
        }
        return solveLockService.getByPid(pid);
    }

    @PostMapping("/{sendTime}")
    public RestObject addOne(@RequestBody SolveLock solveLock, @PathVariable("sendTime") Long sendTime) {
        // 保护措施  以防拿到url一直请求
        if (System.currentTimeMillis() / 1000 - sendTime > 3) {
            return RestObject.builder().code("400").message("请0求时间超时").build();
        }
        return solveLockService.addOne(solveLock);
    }

}
